<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>gettext (Vizi::Translator)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File lib/vizi/vizi_translator.rb, line 38</span>
                <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">gettext</span>(<span class="ruby-identifier">username</span>, <span class="ruby-identifier">password</span>, <span class="ruby-identifier">input_text</span>, <span class="ruby-identifier">output_code</span>)
                        <span class="ruby-identifier">default_src</span> = <span class="ruby-value str">'en'</span>
                        <span class="ruby-identifier">default_action</span> = <span class="ruby-value str">'translateREST'</span>
                
                        <span class="ruby-identifier">input_text</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">input_text</span>)
                        <span class="ruby-keyword kw">begin</span>
                                <span class="ruby-identifier">raise</span> <span class="ruby-constant">UnSupportedLanguage</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">SUPPORTED_LANG_CODES</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">output_code</span>)                 
                                <span class="ruby-identifier">site_url</span> = <span class="ruby-value str">'www.syslang.com'</span>
                                <span class="ruby-identifier">uri_method</span> = <span class="ruby-value str">'/frengly/controller?'</span>
                                <span class="ruby-identifier">uri_string</span> = <span class="ruby-value str">'action='</span><span class="ruby-operator">+</span><span class="ruby-identifier">default_action</span><span class="ruby-operator">+</span><span class="ruby-value str">'&amp;src='</span><span class="ruby-operator">+</span><span class="ruby-identifier">default_src</span><span class="ruby-operator">+</span><span class="ruby-value str">'&amp;dest='</span><span class="ruby-operator">+</span><span class="ruby-identifier">output_code</span><span class="ruby-operator">+</span><span class="ruby-value str">'&amp;text='</span><span class="ruby-operator">+</span><span class="ruby-identifier">input_text</span><span class="ruby-operator">+</span><span class="ruby-value str">'&amp;username='</span><span class="ruby-operator">+</span><span class="ruby-identifier">username</span><span class="ruby-operator">+</span><span class="ruby-value str">'&amp;password='</span><span class="ruby-operator">+</span><span class="ruby-identifier">password</span>
                                <span class="ruby-identifier">response</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get_response</span>(<span class="ruby-identifier">site_url</span>, <span class="ruby-identifier">uri_method</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">uri_string</span>)
                                <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">response</span>.<span class="ruby-identifier">code</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;200&quot;</span>
                                        <span class="ruby-identifier">xml_data</span> = <span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span>
                                        <span class="ruby-identifier">data</span> = <span class="ruby-constant">XmlSimple</span>.<span class="ruby-identifier">xml_in</span>(<span class="ruby-identifier">xml_data</span>)
                                        <span class="ruby-identifier">result</span> = <span class="ruby-identifier">data</span>[<span class="ruby-value str">&quot;translation&quot;</span>][<span class="ruby-value">0</span>]                                            
                                <span class="ruby-keyword kw">else</span>
                                        <span class="ruby-identifier">puts</span> <span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span>
                                        <span class="ruby-identifier">raise</span> <span class="ruby-constant">StandardError</span>, <span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span>
                                <span class="ruby-keyword kw">end</span>
                        <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">UnSupportedLanguage</span>
                                <span class="ruby-identifier">raise</span> <span class="ruby-constant">UnSupportedLanguage</span>.<span class="ruby-identifier">new</span>
                        <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">err_msg</span>
                                <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;#{err_msg}&quot;</span>
                        <span class="ruby-keyword kw">end</span>
                <span class="ruby-keyword kw">end</span></pre>
</body>
</html>